import { defineStore } from 'pinia'
import { store } from '@/store'
interface UserState {
  nickName: string
}

const useUserStore = defineStore('userInfo', {
  state: (): UserState => ({
    nickName: '这是测试',
  }),
  actions: {
    setUserInfo(userInfo: UserState) {
      this.nickName = userInfo.nickName
    },
  },
  // 持久化插件
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'userInfo',
        storage: sessionStorage,
      },
    ],
  },
})

export function useUserStoreHook() {
  return useUserStore(store)
}
